package com.kaiyufound.asset.allocation.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

/**
 * @Author:lihua
 * @Date: 2023-11-07 10:40 星期二
 * @Version v1.0.0
 * @Description:线程池工具类
 */
@Configuration
public class SpringContextTool implements ApplicationContextAware {

    private static final Logger L0GGER = LoggerFactory.getLogger(SpringContextTool.class);

    /**
     * 应用上下文
     */
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextTool.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    /**
     * 是供统一环境变量获入口
     * 系统加载的properties文件
     *
     * @return
     */
    public static String getProperty(String key) {
        return getApplicationContext().getEnvironment().getProperty(key);
    }

    /**
     * 提供统一环境变量获取入口
     * 系统加载的properties文件
     *
     * @param key
     * @param defaultValue
     * @return
     */
    public static String getProperty(String key, String defaultValue) {
        return getApplicationContext().getEnvironment().getProperty(key, defaultValue);
    }

}